package com.s4j.core.manager.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.s4j.core.conset.Constant;
import com.s4j.core.hibernate.CommonDao;
import com.s4j.core.manager.model.SysButton;
import com.s4j.core.manager.model.SysModule;
import com.s4j.core.manager.model.SysProject;
import com.s4j.core.manager.model.SysUser;

@Service
public class ManagerService {
	
	@Resource
	private CommonDao dao;

	public List<SysProject> loadMainLeftTree() {
		String hql = "from SysProject sp where sp.projectType = ? order by sp.sortNum asc";
		List<SysProject> projectTree = dao.findByHQL(hql, SysProject.class, Constant.SYS_PROJECT_TEYE_CLASSIFICATION);
		return projectTree;
	}
	
	public SysModule findModuleByNo(String moduleNo) {
		String hql = "from SysModule sm where sm.moduleNo = ?";
		return dao.findByHQLUnique(hql, SysModule.class, moduleNo);
	}

	public List<SysButton> findButtonByMenu(Long menuId) {
		String hql = "from SysButton sb where sb.menu.menuId = ? order by sb.sortNum asc";
		List<SysButton> buttons = dao.findByHQL(hql, SysButton.class, menuId);
		return buttons;
	}

	public SysUser login(String username, String password) {
		String sql = "from SysUser su where su.userName = ? and su.password = ?";
		SysUser user = dao.findByHQLUnique(sql, SysUser.class, username, password);
		return user;
	}
}
